﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RWLibrary.Logic.Statements;

namespace RWLibrary.Logic
{
    public partial class World
    {
        readonly Dictionary<string, int> _fluentPositionsDictionary = new Dictionary<string, int>();
        readonly List<string>  _fluents = new List<string>();
        readonly Dictionary<string, ActionFamily> _actions = new Dictionary<string,ActionFamily>();
        readonly StatementManager _statements = new StatementManager();


        public bool ContainsFluent(string fluentName)
        {
            return _fluentPositionsDictionary.ContainsKey(fluentName);
        }
        public int FluentPosition(string fluentName)
        {
            return _fluentPositionsDictionary[fluentName];
        }
        public string FluentName(int fluentPosition)
        {
            return _fluents[fluentPosition];
        }
        public void AddFluent(string fluentName)
        {
            if(_fluentPositionsDictionary.ContainsKey(fluentName))
                return;
            if (_actions.ContainsKey(fluentName))
                throw new Exception("There already exists an action called: " + fluentName); ;
            _fluentPositionsDictionary.Add(fluentName, _fluents.Count);
            _fluents.Add(fluentName);
        }

        public int FluentCount { get { return _fluents.Count; } }

        public void AddAction(ActionFamily action)
        {
            if (_fluentPositionsDictionary.ContainsKey(action.Name))
                throw new Exception("There already exists a fluent called: " + action.Name);
            if (_actions.ContainsKey(action.Name))
                return;
            _actions.Add(action.Name, action);
            
        }
        public bool ContainsAction(string actionName)
        {
            return _actions.ContainsKey(actionName);
        }

        public ActionFamily GetAction(string name)
        {
            return _actions[name];
        }

        public StatementManager Statements { get { return _statements; } }

        public List<ActionFamily> ActionsFamilies { get { return _actions.Values.ToList(); } }
   
        
        public State CreateState(int initialValue = 0)
        {
            return new State(this, initialValue);
        }

       
    }
}
